using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;

public partial class StockApiDataController : OnlineDataController
{   
    static StockApiDataController _instance;
    public static StockApiDataController instance
    {
        get
        {
            if (_instance == null)
                _instance = new StockApiDataController();
            return _instance;
        }
    }
    public const string token = "FFDB1431-FDD0-4148-8073-6D8358AF8FEF";
    public override string  getAllStocksDataURL => $"https://stockapi.com.cn/v1/base/all?token={token}";
    public override string getAllTransitionsDataURL(string stock) => $"https://api.biyingapi.com/hszbl/fsjy/{stock}/dn/{token}";
    /// <summary>
    /// 每分钟的主力资金走势
    /// </summary>
    /// <param name="stock"></param>
    /// <returns></returns>
    public override string getZhuLiZiJinURL(string stock) => $"http://api.biyingapi.com/hsmy/zlzj/{stock}/{token}";
    public override string getZiJinLiuRuURL(string stock) => $"http://api.biyingapi.com/hsmy/zjlr/{stock}/{token}";
    public override string getJieDuanZhuLiURL(string stock) => $"http://api.biyingapi.com/hsmy/jddx/{stock}/{token}";
    public override string getChengJiaoFenBuURL(string stock) => $"http://api.biyingapi.com/hsmy/lscj/{stock}/{token}";
    public override string getCompanyFundInfoURL(string stock)
    {
        throw new System.NotImplementedException();
    }


    public override async Task<List<StockData>> RequestAllStocksData()
    {
        var response =  await RequestData<GetAllStocksResponse>(getAllStocksDataURL);
        if (response != null && response.success)
        {
            return response.data.Map(StockApiStockData.StockApiStockData2StockData).AsList();
        }
        else
        {
            Debug.LogError($"获取股票列表失败：{response?.msg}");
            return null;
        }
    }
    public override  async Task<List<TransitionData>> RequestAllTransitionsData(string stockCode)
    {
        return await RequestListData<TransitionData>(getAllTransitionsDataURL(stockCode));
    }
    public override async Task<List<ZhuLiZiJinData>> RequestZhuLiZiJinData(string stockCode)
    {
        return await RequestListData<ZhuLiZiJinData>(getZhuLiZiJinURL(stockCode));
    } 
    public override async Task<List<ZiJinLiuRuData>> RequestZiJinLiuRuData(string stockCode)
    {
        return await RequestListData<ZiJinLiuRuData>(getZiJinLiuRuURL(stockCode));
    }
    public override async Task<List<JieDuanZhuLiData>> RequestJieDuanZhuLiData(string stockCode)
    {
        return await RequestListData<JieDuanZhuLiData>(getJieDuanZhuLiURL(stockCode));
    }
    public override async Task<List<ChengJiaoFenBuData>> RequestChengJiaoFenBuData(string stockCode)
    {
        return await RequestListData<ChengJiaoFenBuData>(getChengJiaoFenBuURL(stockCode));
    }

    public override Task<CompanyFundInfo> RequestCompanyFundInfo(string stockCode)
    {
        throw new System.NotImplementedException();
    }

    #region data

    #endregion
}